home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / What's New? / • What was new 03⁄99 / Development Kits / USBDDK_1.2d3 / USB.h < prev   
Encoding:
C/C++ Source or Header  |  1999-01-19  |  32.4 KB  |  1,191 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        USB.h
  3.  
  4.      Contains:    Public API for USB Services Library (and associated components)
  5.  
  6.      Version:    
  7.  
  8. */
  9. #ifndef __USB__
  10. #define __USB__
  11.  
  12. #ifndef __MACTYPES__
  13. #include <MacTypes.h>
  14. #endif
  15. #ifndef __NAMEREGISTRY__
  16. #include <NameRegistry.h>
  17. #endif
  18. #ifndef __CODEFRAGMENTS__
  19. #include <CodeFragments.h>
  20. #endif
  21. #ifndef __DEVICES__
  22. #include <Devices.h>
  23. #endif
  24.  
  25.  
  26.  
  27. #if PRAGMA_ONCE
  28. #pragma once
  29. #endif
  30.  
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34.  
  35. #if PRAGMA_IMPORT
  36. #pragma import on
  37. #endif
  38.  
  39. #if PRAGMA_STRUCT_ALIGN
  40.     #pragma options align=mac68k
  41. #elif PRAGMA_STRUCT_PACKPUSH
  42.     #pragma pack(push, 2)
  43. #elif PRAGMA_STRUCT_PACK
  44.     #pragma pack(2)
  45. #endif
  46.  
  47. /* ************* Constants ************* */
  48. enum {
  49.     kUSBNoErr                    = 0,
  50.     kUSBNoTran                    = 0,
  51.     kUSBNoDelay                    = 0,
  52.     kUSBPending                    = 1,                            /* */
  53.                                                                 /* USB assigned error numbers in range -6900 .. -6999 */
  54.     kUSBBaseError                = -7000,                        /* */
  55.                                                                 /* USB Services Errors */
  56.     kUSBInternalErr                = -6999,                        /* Internal error */
  57.     kUSBUnknownDeviceErr        = -6998,                        /*  device ref not recognised */
  58.     kUSBUnknownPipeErr            = -6997,                        /*  Pipe ref not recognised */
  59.     kUSBTooManyPipesErr            = -6996,                        /*  Too many pipes */
  60.     kUSBIncorrectTypeErr        = -6995,                        /*  Incorrect type */
  61.     kUSBRqErr                    = -6994,                        /*  Request error */
  62.     kUSBUnknownRequestErr        = -6993,                        /*  Unknown request */
  63.     kUSBTooManyTransactionsErr    = -6992,                        /*  Too many transactions */
  64.     kUSBAlreadyOpenErr            = -6991,                        /*  Already open */
  65.     kUSBNoDeviceErr                = -6990,                        /*  No device */
  66.     kUSBDeviceErr                = -6989,                        /*  Device error */
  67.     kUSBOutOfMemoryErr            = -6988,                        /*  Out of memory */
  68.     kUSBNotFound                = -6987,                        /*  Not found */
  69.     kUSBPBVersionError            = -6986,                        /*  Wrong pbVersion */
  70.     kUSBPBLengthError            = -6985,                        /*  pbLength too small */
  71.     kUSBCompletionError            = -6984,                        /*  no completion routine specified */
  72.     kUSBFlagsError                = -6983,                        /*  Unused flags not zeroed */
  73.     kUSBAbortedError            = -6982,                        /*  Pipe aborted */
  74.     kUSBNoBandwidthError        = -6981,                        /*  Not enough bandwidth available */
  75.     kUSBPipeIdleError            = -6980,                        /*  Pipe is Idle, it will not accept transactions */
  76.     kUSBPipeStalledError        = -6979,                        /*  Pipe has stalled, error needs to be cleared */
  77.     kUSBUnknownInterfaceErr        = -6978,                        /*  Interface ref not recognised */
  78.     kUSBDeviceBusy                = -6977,                        /*  Device is already being configured */
  79.     kUSBDevicePowerProblem        = -6976,                        /*  Device has a power problem */
  80.                                                                 /* */
  81.                                                                 /* USB Manager Errors */
  82.     kUSBBadDispatchTable        = -6950,                        /* Improper driver dispatch table */
  83.     kUSBUnknownNotification        = -6949,                        /* Notification type not defined */
  84.     kUSBQueueFull                = -6948,                        /* Internal queue maxxed */
  85.                                                                 /* */
  86.                                                                 /* Hardware Errors */
  87.                                                                 /* Note pipe stalls are communication */
  88.                                                                 /* errors. The affected pipe can not */
  89.                                                                 /* be used until USBClearPipeStallByReference  */
  90.                                                                 /* is used */
  91.                                                                 /* kUSBEndpointStallErr is returned in */
  92.                                                                 /* response to a stall handshake */
  93.                                                                 /* from a device. The device has to be */
  94.                                                                 /* cleared before a USBClearPipeStallByReference */
  95.                                                                 /* can be used */
  96.     kUSBLinkErr                    = -6916,
  97.     kUSBCRCErr                    = -6915,                        /*  Pipe stall, bad CRC */
  98.     kUSBBitstufErr                = -6914,                        /*  Pipe stall, bitstuffing */
  99.     kUSBDataToggleErr            = -6913,                        /*  Pipe stall, Bad data toggle */
  100.     kUSBEndpointStallErr        = -6912,                        /*  Device didn't understand */
  101.     kUSBNotRespondingErr        = -6911,                        /*  Pipe stall, No device, device hung */
  102.     kUSBPIDCheckErr                = -6910,                        /*  Pipe stall, PID CRC error */
  103.     kUSBWrongPIDErr                = -6909,                        /*  Pipe stall, Bad or wrong PID */
  104.     kUSBOverRunErr                = -6908,                        /*  Packet too large or more data than buffer */
  105.     kUSBUnderRunErr                = -6907,                        /*  Less data than buffer */
  106.     kUSBRes1Err                    = -6906,
  107.     kUSBRes2Err                    = -6905,
  108.     kUSBBufOvrRunErr            = -6904,                        /*  Host hardware failure on data in, PCI busy? */
  109.     kUSBBufUnderRunErr            = -6903,                        /*  Host hardware failure on data out, PCI busy? */
  110.     kUSBNotSent1Err                = -6902,                        /*  Transaction not sent */
  111.     kUSBNotSent2Err                = -6901                            /*  Transaction not sent */
  112. };
  113.  
  114. enum {
  115.                                                                 /* Flags */
  116.     kUSBTaskTimeFlag            = 1,
  117.     kUSBHubPower                = 2,
  118.     kUSBPowerReset                = 4,
  119.     kUSBHubReaddress            = 8,
  120.     kUSBAddressRequest            = 16
  121. };
  122.  
  123. enum {
  124.                                                                 /* Hub messages */
  125.     kUSBHubPortResetRequest        = 1
  126. };
  127.  
  128. /* ************* types ************* */
  129.  
  130. typedef SInt32                             USBReference;
  131. typedef USBReference                     USBDeviceRef;
  132. typedef USBReference                     USBInterfaceRef;
  133. typedef USBReference                     USBPipeRef;
  134. typedef USBReference                     USBBusRef;
  135. typedef UInt32                             USBPipeState;
  136. typedef UInt32                             USBCount;
  137. typedef UInt32                             USBFlags;
  138. typedef UInt8                             USBRequest;
  139. typedef UInt8                             USBDirection;
  140. typedef UInt8                             USBRqRecipient;
  141. typedef UInt8                             USBRqType;
  142. typedef UInt16                             USBRqIndex;
  143. typedef UInt16                             USBRqValue;
  144.  
  145.  
  146.  
  147. struct usbControlBits {
  148.     UInt8                             BMRequestType;
  149.     UInt8                             BRequest;
  150.     USBRqValue                         WValue;
  151.     USBRqIndex                         WIndex;
  152.     UInt16                             reserved4;
  153. };
  154. typedef struct usbControlBits            usbControlBits;
  155.  
  156. struct USBIsocFrame {
  157.     OSStatus                         frStatus;
  158.     UInt16                             frReqCount;
  159.     UInt16                             frActCount;
  160. };
  161. typedef struct USBIsocFrame                USBIsocFrame;
  162.  
  163. struct usbIsocBits {
  164.     USBIsocFrame *                    FrameList;
  165.     UInt32                             NumFrames;
  166. };
  167. typedef struct usbIsocBits                usbIsocBits;
  168.  
  169. struct usbHubBits {
  170.     UInt32                             Request;
  171.     UInt32                             Spare;
  172. };
  173. typedef struct usbHubBits                usbHubBits;
  174. typedef struct USBPB                     USBPB;
  175. typedef CALLBACK_API_C( void , USBCompletion )(USBPB *pb);
  176.  
  177. struct USBPB {
  178.  
  179.     void *                            qlink;
  180.     UInt16                             qType;
  181.     UInt16                             pbLength;
  182.     UInt16                             pbVersion;
  183.     UInt16                             reserved1;
  184.     UInt32                             reserved2;
  185.  
  186.     OSStatus                         usbStatus;
  187.     USBCompletion                     usbCompletion;
  188.     UInt32                             usbRefcon;
  189.  
  190.     USBReference                     usbReference;
  191.  
  192.     void *                            usbBuffer;
  193.     USBCount                         usbReqCount;
  194.     USBCount                         usbActCount;
  195.  
  196.     USBFlags                         usbFlags;
  197.  
  198.     union{
  199.  
  200.     usbControlBits                     cntl;
  201.  
  202.  
  203.     usbIsocBits                        isoc;
  204.  
  205.     usbHubBits                        hub;
  206.  
  207.     }usb;
  208.  
  209.     UInt32                             usbFrame;
  210.  
  211.     UInt8                             usbClassType;
  212.     UInt8                             usbSubclass;
  213.     UInt8                             usbProtocol;
  214.     UInt8                             usbOther;
  215.  
  216.     UInt32                             reserved6;
  217.     UInt16                             reserved7;
  218.     UInt16                             reserved8;
  219.  
  220. };
  221.  
  222. #if !defined(OLDUSBNAMES)
  223. #define OLDUSBNAMES 0
  224. #endif
  225.  
  226. #if OLDUSBNAMES
  227. #define usbBMRequestType  usb.cntl.BMRequestType
  228. #define usbBRequest       usb.cntl.BRequest
  229. #define usbWValue         usb.cntl.WValue
  230. #define usbWIndex         usb.cntl.WIndex
  231. #endif
  232.  
  233. struct uslReq {
  234.     USBDirection                     usbDirection;
  235.     USBRqType                         usbType;
  236.     USBRqRecipient                     usbRecipient;
  237.     USBRequest                         usbRequest;
  238. };
  239. typedef struct uslReq                    uslReq;
  240.  
  241. enum {
  242.                                                                 /* BT 19Aug98, bump up to v1.10 for Isoc*/
  243.     kUSBCurrentPBVersion        = 0x0100,                        /* v1.00*/
  244.     kUSBIsocPBVersion            = 0x0109,                        /* v1.10*/
  245.     kUSBCurrentHubPB            = kUSBIsocPBVersion
  246. };
  247.  
  248.  
  249.  
  250.  
  251. #define kUSBNoCallBack ((USBCompletion)-1L)
  252.  
  253.  
  254. typedef UInt8                             bcdUSB;
  255. enum {
  256.     kUSBControl                    = 0,
  257.     kUSBIsoc                    = 1,
  258.     kUSBBulk                    = 2,
  259.     kUSBInterrupt                = 3,
  260.     kUSBAnyType                    = 0xFF
  261. };
  262.  
  263. /* endpoint type */
  264. enum {
  265.     kUSBOut                        = 0,
  266.     kUSBIn                        = 1,
  267.     kUSBNone                    = 2,
  268.     kUSBAnyDirn                    = 3
  269. };
  270.  
  271. /*USBDirection*/
  272. enum {
  273.     kUSBStandard                = 0,
  274.     kUSBClass                    = 1,
  275.     kUSBVendor                    = 2
  276. };
  277.  
  278. /*USBRqType*/
  279. enum {
  280.     kUSBDevice                    = 0,
  281.     kUSBInterface                = 1,
  282.     kUSBEndpoint                = 2,
  283.     kUSBOther                    = 3
  284. };
  285.  
  286. /*USBRqRecipient*/
  287. enum {
  288.     kUSBRqGetStatus                = 0,
  289.     kUSBRqClearFeature            = 1,
  290.     kUSBRqReserved1                = 2,
  291.     kUSBRqSetFeature            = 3,
  292.     kUSBRqReserved2                = 4,
  293.     kUSBRqSetAddress            = 5,
  294.     kUSBRqGetDescriptor            = 6,
  295.     kUSBRqSetDescriptor            = 7,
  296.     kUSBRqGetConfig                = 8,
  297.     kUSBRqSetConfig                = 9,
  298.     kUSBRqGetInterface            = 10,
  299.     kUSBRqSetInterface            = 11,
  300.     kUSBRqSyncFrame                = 12
  301. };
  302.  
  303. /*USBRequest*/
  304.  
  305. enum {
  306.     kUSBDeviceDesc                = 1,
  307.     kUSBConfDesc                = 2,
  308.     kUSBStringDesc                = 3,
  309.     kUSBInterfaceDesc            = 4,
  310.     kUSBEndpointDesc            = 5,
  311.     kUSBHIDDesc                    = 0x21,
  312.     kUSBReportDesc                = 0x22,
  313.     kUSBPhysicalDesc            = 0x23,
  314.     kUSBHUBDesc                    = 0x29
  315. };
  316.  
  317. /* descriptorType */
  318.  
  319. enum {
  320.     kUSBFeatureDeviceRemoteWakeup = 1,
  321.     kUSBFeatureEndpointStall    = 0
  322. };
  323.  
  324. /* Feature selectors */
  325. enum {
  326.     kUSBActive                    = 0,                            /* Pipe can accept new transactions*/
  327.     kUSBIdle                    = 1,                            /* Pipe will not accept new transactions*/
  328.     kUSBStalled                    = 2                                /* An error occured on the pipe*/
  329. };
  330.  
  331. enum {
  332.     kUSB100mAAvailable            = 50,
  333.     kUSB500mAAvailable            = 250,
  334.     kUSB100mA                    = 50,
  335.     kUSBAtrBusPowered            = 0x80,
  336.     kUSBAtrSelfPowered            = 0x40,
  337.     kUSBAtrRemoteWakeup            = 0x20
  338. };
  339.  
  340. enum {
  341.     kUSBRel10                    = 0x0100
  342. };
  343.  
  344. #define USB_CONSTANT16(x)    ((((x) >> 8) & 0x0ff) | ((x & 0xff) << 8))
  345. enum {
  346.     kUSBDeviceDescriptorLength    = 0x12,
  347.     kUSBInterfaceDescriptorLength = 0x09
  348. };
  349.  
  350.  
  351. struct USBDeviceDescriptor {
  352.     UInt8                             length;
  353.     UInt8                             descType;
  354.     UInt16                             usbRel;
  355.     UInt8                             deviceClass;
  356.     UInt8                             deviceSubClass;
  357.     UInt8                             protocol;
  358.     UInt8                             maxPacketSize;
  359.     UInt16                             vendor;
  360.     UInt16                             product;
  361.     UInt16                             devRel;
  362.     UInt8                             manuIdx;
  363.     UInt8                             prodIdx;
  364.     UInt8                             serialIdx;
  365.     UInt8                             numConf;
  366.     UInt16                             descEnd;                    /* was "end", but this is reserved in some languages*/
  367. };
  368. typedef struct USBDeviceDescriptor        USBDeviceDescriptor;
  369. #ifndef OLDCLASSNAMES
  370. #ifndef __cplusplus
  371. #define class deviceClass
  372. #define subClass deviceSubClass
  373. #endif
  374. #endif
  375. typedef USBDeviceDescriptor *            USBDeviceDescriptorPtr;
  376.  
  377. struct USBDescriptorHeader {
  378.     UInt8                             length;
  379.     UInt8                             descriptorType;
  380. };
  381. typedef struct USBDescriptorHeader        USBDescriptorHeader;
  382. typedef USBDescriptorHeader *            USBDescriptorHeaderPtr;
  383.  
  384. struct USBConfigurationDescriptor {
  385.     UInt8                             length;
  386.     UInt8                             descriptorType;
  387.     UInt16                             totalLength;
  388.     UInt8                             numInterfaces;
  389.     UInt8                             configValue;
  390.     UInt8                             configStrIndex;
  391.     UInt8                             attributes;
  392.     UInt8                             maxPower;
  393. };
  394. typedef struct USBConfigurationDescriptor USBConfigurationDescriptor;
  395. typedef USBConfigurationDescriptor *    USBConfigurationDescriptorPtr;
  396.  
  397. struct USBInterfaceDescriptor {
  398.     UInt8                             length;
  399.     UInt8                             descriptorType;
  400.     UInt8                             interfaceNumber;
  401.     UInt8                             alternateSetting;
  402.     UInt8                             numEndpoints;
  403.     UInt8                             interfaceClass;
  404.     UInt8                             interfaceSubClass;
  405.     UInt8                             interfaceProtocol;
  406.     UInt8                             interfaceStrIndex;
  407. };
  408. typedef struct USBInterfaceDescriptor    USBInterfaceDescriptor;
  409. typedef USBInterfaceDescriptor *        USBInterfaceDescriptorPtr;
  410.  
  411. struct USBEndPointDescriptor {
  412.     UInt8                             length;
  413.     UInt8                             descriptorType;
  414.     UInt8                             endpointAddress;
  415.     UInt8                             attributes;
  416.     UInt16                             maxPacketSize;
  417.     UInt8                             interval;
  418. };
  419. typedef struct USBEndPointDescriptor    USBEndPointDescriptor;
  420. typedef USBEndPointDescriptor *            USBEndPointDescriptorPtr;
  421.  
  422. struct USBHIDDescriptor {
  423.     UInt8                             descLen;
  424.     UInt8                             descType;
  425.     UInt16                             descVersNum;
  426.     UInt8                             hidCountryCode;
  427.     UInt8                             hidNumDescriptors;
  428.     UInt8                             hidDescriptorType;
  429.     UInt8                             hidDescriptorLengthLo;        /* can't make this a single 16bit value or the compiler will add a filler byte*/
  430.     UInt8                             hidDescriptorLengthHi;
  431. };
  432. typedef struct USBHIDDescriptor            USBHIDDescriptor;
  433. typedef USBHIDDescriptor *                USBHIDDescriptorPtr;
  434.  
  435. struct USBHIDReportDesc {
  436.     UInt8                             hidDescriptorType;
  437.     UInt8                             hidDescriptorLengthLo;        /* can't make this a single 16bit value or the compiler will add a filler byte*/
  438.     UInt8                             hidDescriptorLengthHi;
  439. };
  440. typedef struct USBHIDReportDesc            USBHIDReportDesc;
  441. typedef USBHIDReportDesc *                USBHIDReportDescPtr;
  442.  
  443. struct USBHubPortStatus {
  444.     UInt16                             portFlags;                    /* Port status flags */
  445.     UInt16                             portChangeFlags;            /* Port changed flags */
  446. };
  447. typedef struct USBHubPortStatus            USBHubPortStatus;
  448. typedef USBHubPortStatus *                USBHubPortStatusPtr;
  449. /* ********* ProtoTypes *************** */
  450. /* For dealing with endianisms */
  451. EXTERN_API_C( UInt16 )
  452. HostToUSBWord                    (UInt16                 value);
  453.  
  454. EXTERN_API_C( UInt16 )
  455. USBToHostWord                    (UInt16                 value);
  456.  
  457. EXTERN_API_C( UInt32 )
  458. HostToUSBLong                    (UInt32                 value);
  459.  
  460. EXTERN_API_C( UInt32 )
  461. USBToHostLong                    (UInt32                 value);
  462.  
  463. /* Main prototypes */
  464. /* Transfer commands */
  465. EXTERN_API_C( OSStatus )
  466. USBDeviceRequest                (USBPB *                pb);
  467.  
  468. EXTERN_API_C( OSStatus )
  469. USBOpenPipe                        (USBPB *                pb);
  470.  
  471. EXTERN_API_C( OSStatus )
  472. USBClosePipe                    (USBPB *                pb);
  473.  
  474. EXTERN_API_C( OSStatus )
  475. USBBulkWrite                    (USBPB *                pb);
  476.  
  477. EXTERN_API_C( OSStatus )
  478. USBBulkRead                        (USBPB *                pb);
  479.  
  480. EXTERN_API_C( OSStatus )
  481. USBIntRead                        (USBPB *                pb);
  482.  
  483. EXTERN_API_C( OSStatus )
  484. USBIsocRead                        (USBPB *                pb);
  485.  
  486. EXTERN_API_C( OSStatus )
  487. USBIsocWrite                    (USBPB *                pb);
  488.  
  489. /* Pipe state control */
  490. EXTERN_API_C( OSStatus )
  491. USBClearPipeStallByReference    (USBPipeRef             ref);
  492.  
  493. EXTERN_API_C( OSStatus )
  494. USBAbortPipeByReference            (USBReference             ref);
  495.  
  496. EXTERN_API_C( OSStatus )
  497. USBResetPipeByReference            (USBReference             ref);
  498.  
  499. EXTERN_API_C( OSStatus )
  500. USBSetPipeIdleByReference        (USBPipeRef             ref);
  501.  
  502. EXTERN_API_C( OSStatus )
  503. USBSetPipeActiveByReference        (USBPipeRef             ref);
  504.  
  505. EXTERN_API_C( OSStatus )
  506. USBClosePipeByReference            (USBPipeRef             ref);
  507.  
  508. EXTERN_API_C( OSStatus )
  509. USBGetPipeStatusByReference        (USBReference             ref,
  510.                                  USBPipeState *            state);
  511.  
  512.  
  513. /* Configuration services */
  514. EXTERN_API_C( OSStatus )
  515. USBFindNextInterface            (USBPB *                pb);
  516.  
  517. EXTERN_API_C( OSStatus )
  518. USBOpenDevice                    (USBPB *                pb);
  519.  
  520. EXTERN_API_C( OSStatus )
  521. USBSetConfiguration                (USBPB *                pb);
  522.  
  523. EXTERN_API_C( OSStatus )
  524. USBNewInterfaceRef                (USBPB *                pb);
  525.  
  526. EXTERN_API_C( OSStatus )
  527. USBDisposeInterfaceRef            (USBPB *                pb);
  528.  
  529. EXTERN_API_C( OSStatus )
  530. USBConfigureInterface            (USBPB *                pb);
  531.  
  532. EXTERN_API_C( OSStatus )
  533. USBFindNextPipe                    (USBPB *                pb);
  534.  
  535.  
  536. /* Dealing with descriptors. */
  537. /* Note most of this is temprorary */
  538. EXTERN_API_C( OSStatus )
  539. USBGetConfigurationDescriptor    (USBPB *                pb);
  540.  
  541. EXTERN_API_C( OSStatus )
  542. USBGetFullConfigurationDescriptor (USBPB *                pb);
  543.  
  544. EXTERN_API_C( OSStatus )
  545. USBFindNextEndpointDescriptorImmediate (USBPB *            pb);
  546.  
  547. EXTERN_API_C( OSStatus )
  548. USBFindNextInterfaceDescriptorImmediate (USBPB *        pb);
  549.  
  550. EXTERN_API_C( OSStatus )
  551. USBFindNextAssociatedDescriptor    (USBPB *                pb);
  552.  
  553.  
  554.  
  555. /* Utility functions */
  556. EXTERN_API_C( OSStatus )
  557. USBResetDevice                    (USBPB *                pb);
  558.  
  559. EXTERN_API_C( OSStatus )
  560. USBGetFrameNumberImmediate        (USBPB *                pb);
  561.  
  562. EXTERN_API_C( OSStatus )
  563. USBDelay                        (USBPB *                pb);
  564.  
  565. EXTERN_API_C( OSStatus )
  566. USBAllocMem                        (USBPB *                pb);
  567.  
  568. EXTERN_API_C( OSStatus )
  569. USBDeallocMem                    (USBPB *                pb);
  570.  
  571. /* Expert interface functions */
  572. EXTERN_API_C( OSStatus )
  573. USBExpertInstallInterfaceDriver    (USBDeviceRef             ref,
  574.                                  USBDeviceDescriptorPtr  desc,
  575.                                  USBInterfaceDescriptorPtr  interfacePtr,
  576.                                  USBReference             hubRef,
  577.                                  UInt32                 busPowerAvailable);
  578.  
  579. EXTERN_API_C( OSStatus )
  580. USBExpertRemoveInterfaceDriver    (USBDeviceRef             ref);
  581.  
  582. EXTERN_API_C( OSStatus )
  583. USBExpertInstallDeviceDriver    (USBDeviceRef             ref,
  584.                                  USBDeviceDescriptorPtr  desc,
  585.                                  USBReference             hubRef,
  586.                                  UInt32                 port,
  587.                                  UInt32                 busPowerAvailable);
  588.  
  589. EXTERN_API_C( OSStatus )
  590. USBExpertRemoveDeviceDriver        (USBDeviceRef             ref);
  591.  
  592. EXTERN_API_C( OSStatus )
  593. USBExpertStatus                    (USBDeviceRef             ref,
  594.                                  void *                    pointer,
  595.                                  UInt32                 value);
  596.  
  597. EXTERN_API_C( OSStatus )
  598. USBExpertFatalError                (USBDeviceRef             ref,
  599.                                  OSStatus                 status,
  600.                                  void *                    pointer,
  601.                                  UInt32                 value);
  602.  
  603. EXTERN_API_C( OSStatus )
  604. USBExpertNotify                    (void *                    note);
  605.  
  606. EXTERN_API_C( OSStatus )
  607. USBExpertStatusLevel            (UInt32                 level,
  608.                                  USBDeviceRef             ref,
  609.                                  char *                    status,
  610.                                  UInt32                 value);
  611.  
  612. EXTERN_API_C( OSStatus )
  613. USBExpertSetDevicePowerStatus    (USBDeviceRef             ref,
  614.                                  UInt32                 reserved1,
  615.                                  UInt32                 reserved2,
  616.                                  UInt32                 powerStatus,
  617.                                  UInt32                 busPowerAvailable,
  618.                                  UInt32                 busPowerNeeded);
  619.  
  620. enum {
  621.     kUSBDevicePower_PowerOK        = 0,
  622.     kUSBDevicePower_BusPowerInsufficient = 1,
  623.     kUSBDevicePower_BusPowerNotAllFeatures = 2,
  624.     kUSBDevicePower_SelfPowerInsufficient = 3,
  625.     kUSBDevicePower_SelfPowerNotAllFeatures = 4,
  626.     kUSBDevicePower_HubPortOk    = 5,
  627.     kUSBDevicePower_HubPortOverCurrent = 6,
  628.     kUSBDevicePower_BusPoweredHubOnLowPowerPort = 7,
  629.     kUSBDevicePower_BusPoweredHubToBusPoweredHub = 8,
  630.     kUSBDevicePower_Reserved3    = 9,
  631.     kUSBDevicePower_Reserved4    = 10
  632. };
  633.  
  634.  
  635. /* For hubs only */
  636. EXTERN_API_C( OSStatus )
  637. USBHubAddDevice                    (USBPB *                pb);
  638.  
  639. EXTERN_API_C( OSStatus )
  640. USBHubConfigurePipeZero            (USBPB *                pb);
  641.  
  642. EXTERN_API_C( OSStatus )
  643. USBHubSetAddress                (USBPB *                pb);
  644.  
  645. EXTERN_API_C( OSStatus )
  646. USBHubDeviceRemoved                (USBPB *                pb);
  647.  
  648.  
  649. EXTERN_API_C( UInt8 )
  650. USBMakeBMRequestType            (UInt8                     direction,
  651.                                  UInt8                     reqtype,
  652.                                  UInt8                     recipient);
  653.  
  654. EXTERN_API_C( OSStatus )
  655. USBControlRequest                (USBPB *                pb);
  656.  
  657.  
  658. typedef UInt32                             USBLocationID;
  659. enum {
  660.     kUSBLocationNibbleFormat    = 0                                /* Other values are reserved for future types (like when we have more than 16 ports per hub)*/
  661. };
  662.  
  663.  
  664. enum {
  665.     kNoDeviceRef                = -1
  666. };
  667.  
  668. /* Expert Notification Types*/
  669. typedef UInt8                             USBNotificationType;
  670. typedef UInt8                             USBDriverMessage;
  671. enum {
  672.     kNotifyAddDevice            = 0x00,
  673.     kNotifyRemoveDevice            = 0x01,
  674.     kNotifyAddInterface            = 0x02,
  675.     kNotifyRemoveInterface        = 0x03,
  676.     kNotifyGetDeviceDescriptor    = 0x04,
  677.     kNotifyGetInterfaceDescriptor = 0x05,
  678.     kNotifyGetNextDeviceByClass    = 0x06,
  679.     kNotifyGetDriverConnectionID = 0x07,
  680.     kNotifyInstallDeviceNotification = 0x08,
  681.     kNotifyRemoveDeviceNotification = 0x09,
  682.     kNotifyDeviceRefToBusRef    = 0x0A,
  683.     kNotifyDriverNotify            = 0x0C,
  684.     kNotifyParentNotify            = 0x0D,
  685.     kNotifyAnyEvent                = 0xFF,
  686.     kNotifyPowerState            = 0x17,
  687.     kNotifyStatus                = 0x18,
  688.     kNotifyFatalError            = 0x19
  689. };
  690.  
  691. /*
  692.    USB Manager wildcard constants for USBGetNextDeviceByClass
  693.    and USBInstallDeviceNotification.
  694. */
  695. typedef UInt16                             USBManagerWildcard;
  696. enum {
  697.     kUSBAnyClass                = 0xFFFF,
  698.     kUSBAnySubClass                = 0xFFFF,
  699.     kUSBAnyProtocol                = 0xFFFF,
  700.     kUSBAnyVendor                = 0xFFFF,
  701.     kUSBAnyProduct                = 0xFFFF
  702. };
  703.  
  704.  
  705.  
  706.  
  707. struct ExpertNotificationData {
  708.     USBNotificationType             notification;
  709.     UInt8                             filler[1];                    /* unused due to 2-byte 68k alignment*/
  710.     USBDeviceRef *                    deviceRef;
  711.     UInt32                             busPowerAvailable;
  712.     void *                            data;
  713.     UInt32                             info1;
  714.     UInt32                             info2;
  715. };
  716. typedef struct ExpertNotificationData    ExpertNotificationData;
  717. typedef ExpertNotificationData *        ExpertNotificationDataPtr;
  718. /* Definition of function pointer passed in ExpertEntryProc*/
  719. typedef CALLBACK_API_C( OSStatus , ExpertNotificationProcPtr )(ExpertNotificationDataPtr pNotificationData);
  720. /* Definition of expert's callback installation function*/
  721. typedef CALLBACK_API_C( OSStatus , ExpertEntryProcPtr )(ExpertNotificationProcPtr pExpertNotify);
  722. /* Device Notification Callback Routine*/
  723. typedef CALLBACK_API_C( void , USBDeviceNotificationCallbackProcPtr )(void *pb);
  724. /* Device Notification Parameter Block*/
  725.  
  726. struct USBDeviceNotificationParameterBlock {
  727.     UInt16                             pbLength;
  728.     UInt16                             pbVersion;
  729.     USBNotificationType             usbDeviceNotification;
  730.     UInt8                             reserved1[1];                /* needed because of 2-byte 68k alignment*/
  731.     USBDeviceRef                     usbDeviceRef;
  732.     UInt16                             usbClass;
  733.     UInt16                             usbSubClass;
  734.     UInt16                             usbProtocol;
  735.     UInt16                             usbVendor;
  736.     UInt16                             usbProduct;
  737.     OSStatus                         result;
  738.     UInt32                             token;
  739.     USBDeviceNotificationCallbackProcPtr  callback;
  740.     UInt32                             refcon;
  741. };
  742. typedef struct USBDeviceNotificationParameterBlock USBDeviceNotificationParameterBlock;
  743. /* Forward declaration*/
  744. typedef USBDeviceNotificationParameterBlock * USBDeviceNotificationParameterBlockPtr;
  745. /* Definition of USBDriverNotificationCallback Routine*/
  746. typedef CALLBACK_API_C( void , USBDriverNotificationCallbackPtr )(OSStatus status, UInt32 refcon);
  747. /* Public Functions*/
  748. EXTERN_API_C( OSStatus )
  749. USBGetNextDeviceByClass            (USBDeviceRef *            deviceRef,
  750.                                  CFragConnectionID *    connID,
  751.                                  UInt16                 theClass,
  752.                                  UInt16                 theSubClass,
  753.                                  UInt16                 theProtocol);
  754.  
  755. EXTERN_API_C( OSStatus )
  756. USBGetDeviceDescriptor            (USBDeviceRef *            deviceRef,
  757.                                  USBDeviceDescriptor *    deviceDescriptor,
  758.                                  UInt32                 size);
  759.  
  760. EXTERN_API_C( OSStatus )
  761. USBGetInterfaceDescriptor        (USBInterfaceRef *        interfaceRef,
  762.                                  USBInterfaceDescriptor * interfaceDescriptor,
  763.                                  UInt32                 size);
  764.  
  765. EXTERN_API_C( OSStatus )
  766. USBGetDriverConnectionID        (USBDeviceRef *            deviceRef,
  767.                                  CFragConnectionID *    connID);
  768.  
  769. EXTERN_API_C( void )
  770. USBInstallDeviceNotification    (USBDeviceNotificationParameterBlock * pb);
  771.  
  772. EXTERN_API_C( OSStatus )
  773. USBRemoveDeviceNotification        (UInt32                 token);
  774.  
  775. EXTERN_API_C( OSStatus )
  776. USBDeviceRefToBusRef            (USBDeviceRef *            deviceRef,
  777.                                  USBBusRef *            busRef);
  778.  
  779. EXTERN_API_C( OSStatus )
  780. USBDriverNotify                    (USBReference             reference,
  781.                                  USBDriverMessage         mesg,
  782.                                  UInt32                 refcon,
  783.                                  USBDriverNotificationCallbackPtr  callback);
  784.  
  785. EXTERN_API_C( OSStatus )
  786. USBExpertNotifyParent            (USBReference             reference,
  787.                                  void *                    pointer);
  788.  
  789. typedef CALLBACK_API_C( void , HIDInterruptProcPtr )(UInt32 refcon, void *theData);
  790. /* HID Install Interrupt prototype*/
  791. typedef CALLBACK_API_C( OSStatus , USBHIDInstallInterruptProcPtr )(HIDInterruptProcPtr pInterruptProc, UInt32 refcon);
  792. /* HID Poll Device prototype*/
  793. typedef CALLBACK_API_C( OSStatus , USBHIDPollDeviceProcPtr )(void );
  794. /* HID Control Device prototype*/
  795. typedef CALLBACK_API_C( OSStatus , USBHIDControlDeviceProcPtr )(UInt32 theControlSelector, void *theControlData);
  796. /* HID Get Device Info prototype*/
  797. typedef CALLBACK_API_C( OSStatus , USBHIDGetDeviceInfoProcPtr )(UInt32 theInfoSelector, void *theInfo);
  798. /* HID Enter Polled Mode prototype*/
  799. typedef CALLBACK_API_C( OSStatus , USBHIDEnterPolledModeProcPtr )(void );
  800. /* HID Exit Polled Mode prototype*/
  801. typedef CALLBACK_API_C( OSStatus , USBHIDExitPolledModeProcPtr )(void );
  802.  
  803. struct USBHIDModuleDispatchTable {
  804.     UInt32                             hidDispatchVersion;
  805.     USBHIDInstallInterruptProcPtr     pUSBHIDInstallInterrupt;
  806.     USBHIDPollDeviceProcPtr         pUSBHIDPollDevice;
  807.     USBHIDControlDeviceProcPtr         pUSBHIDControlDevice;
  808.     USBHIDGetDeviceInfoProcPtr         pUSBHIDGetDeviceInfo;
  809.     USBHIDEnterPolledModeProcPtr     pUSBHIDEnterPolledMode;
  810.     USBHIDExitPolledModeProcPtr     pUSBHIDExitPolledMode;
  811. };
  812. typedef struct USBHIDModuleDispatchTable USBHIDModuleDispatchTable;
  813. typedef USBHIDModuleDispatchTable *        USBHIDModuleDispatchTablePtr;
  814. /*    Prototypes Tue, Mar 17, 1998 4:54:30 PM    */
  815. EXTERN_API_C( OSStatus )
  816. USBHIDInstallInterrupt            (HIDInterruptProcPtr     HIDInterruptFunction,
  817.                                  UInt32                 refcon);
  818.  
  819. EXTERN_API_C( OSStatus )
  820. USBHIDPollDevice                (void);
  821.  
  822. EXTERN_API_C( OSStatus )
  823. USBHIDControlDevice                (UInt32                 theControlSelector,
  824.                                  void *                    theControlData);
  825.  
  826. EXTERN_API_C( OSStatus )
  827. USBHIDGetDeviceInfo                (UInt32                 theInfoSelector,
  828.                                  void *                    theInfo);
  829.  
  830. EXTERN_API_C( OSStatus )
  831. USBHIDEnterPolledMode            (void);
  832.  
  833. EXTERN_API_C( OSStatus )
  834. USBHIDExitPolledMode            (void);
  835.  
  836. EXTERN_API_C( void )
  837. HIDNotification                    (UInt32                 devicetype,
  838.                                  UInt8                     NewHIDData[],
  839.                                  UInt8                     OldHIDData[]);
  840.  
  841. enum {
  842.     kHIDRqGetReport                = 1,
  843.     kHIDRqGetIdle                = 2,
  844.     kHIDRqGetProtocol            = 3,
  845.     kHIDRqSetReport                = 9,
  846.     kHIDRqSetIdle                = 10,
  847.     kHIDRqSetProtocol            = 11
  848. };
  849.  
  850. enum {
  851.     kHIDRtInputReport            = 1,
  852.     kHIDRtOutputReport            = 2,
  853.     kHIDRtFeatureReport            = 3
  854. };
  855.  
  856. enum {
  857.     kHIDBootProtocolValue        = 0,
  858.     kHIDReportProtocolValue        = 1
  859. };
  860.  
  861. enum {
  862.     kHIDKeyboardInterfaceProtocol = 1,
  863.     kHIDMouseInterfaceProtocol    = 2
  864. };
  865.  
  866. enum {
  867.     kHIDSetLEDStateByBits        = 1,
  868.     kHIDSetLEDStateByBitMask    = 1,
  869.     kHIDSetLEDStateByIDNumber    = 2,
  870.     kHIDRemoveInterruptHandler    = 3,
  871.     kHIDEnableDemoMode            = 4,
  872.     kHIDDisableDemoMode            = 5
  873. };
  874.  
  875. enum {
  876.     kHIDGetLEDStateByBits        = 1,                            /* not supported in 1.0 of keyboard module*/
  877.     kHIDGetLEDStateByBitMask    = 1,                            /* not supported in 1.0 of keyboard module*/
  878.     kHIDGetLEDStateByIDNumber    = 2,
  879.     kHIDGetDeviceCountryCode    = 3,                            /* not supported in 1.0 HID modules*/
  880.     kHIDGetDeviceUnitsPerInch    = 4,                            /* only supported in mouse HID module*/
  881.     kHIDGetInterruptHandler        = 5,
  882.     kHIDGetCurrentKeys            = 6,                            /* only supported in keyboard HID module*/
  883.     kHIDGetInterruptRefcon        = 7,
  884.     kHIDGetVendorID                = 8,
  885.     kHIDGetProductID            = 9
  886. };
  887.  
  888.  
  889. enum {
  890.     kNumLockLED                    = 0,
  891.     kCapsLockLED                = 1,
  892.     kScrollLockLED                = 2,
  893.     kComposeLED                    = 3,
  894.     kKanaLED                    = 4
  895. };
  896.  
  897. enum {
  898.     kNumLockLEDMask                = 1 << kNumLockLED,
  899.     kCapsLockLEDMask            = 1 << kCapsLockLED,
  900.     kScrollLockLEDMask            = 1 << kScrollLockLED,
  901.     kComposeLEDMask                = 1 << kComposeLED,
  902.     kKanaLEDMask                = 1 << kKanaLED
  903. };
  904.  
  905. enum {
  906.     kUSBCapsLockKey                = 0x39,
  907.     kUSBNumLockKey                = 0x53,
  908.     kUSBScrollLockKey            = 0x47
  909. };
  910.  
  911.  
  912. struct USBMouseData {
  913.     UInt16                             buttons;
  914.     SInt16                             XDelta;
  915.     SInt16                             YDelta;
  916. };
  917. typedef struct USBMouseData                USBMouseData;
  918. typedef USBMouseData *                    USBMouseDataPtr;
  919.  
  920. struct USBKeyboardData {
  921.     UInt16                             keycount;
  922.     UInt16                             usbkeycode[32];
  923. };
  924. typedef struct USBKeyboardData            USBKeyboardData;
  925. typedef USBKeyboardData *                USBKeyboardDataPtr;
  926.  
  927. union USBHIDData {
  928.     USBKeyboardData                 kbd;
  929.     USBMouseData                     mouse;
  930. };
  931. typedef union USBHIDData                USBHIDData;
  932. typedef USBHIDData *                    USBHIDDataPtr;
  933. EXTERN_API_C( void )
  934. StartCompoundClassDriver        (USBDeviceRef             device,
  935.                                  UInt16                 classID,
  936.                                  UInt16                 subClass);
  937.  
  938. enum {
  939.     kUSBCompositeClass            = 0,
  940.     kUSBAudioClass                = 1,
  941.     kUSBCommClass                = 2,
  942.     kUSBHIDClass                = 3,
  943.     kUSBDisplayClass            = 4,
  944.     kUSBPrintingClass            = 7,
  945.     kUSBMassStorageClass        = 8,
  946.     kUSBHubClass                = 9,
  947.     kUSBDataClass                = 10,
  948.     kUSBVendorSpecificClass        = 0xFF
  949. };
  950.  
  951. enum {
  952.     kUSBCompositeSubClass        = 0,
  953.     kUSBHubSubClass                = 1,
  954.     kUSBPrinterSubclass            = 1
  955. };
  956.  
  957. enum {
  958.     kUSBHIDInterfaceClass        = 0x03
  959. };
  960.  
  961. enum {
  962.     kUSBNoInterfaceSubClass        = 0x00,
  963.     kUSBBootInterfaceSubClass    = 0x01
  964. };
  965.  
  966. enum {
  967.     kUSBNoInterfaceProtocol        = 0x00,
  968.     kUSBKeyboardInterfaceProtocol = 0x01,
  969.     kUSBMouseInterfaceProtocol    = 0x02
  970. };
  971.  
  972. enum {
  973.     kUSBPrinterUnidirectionalProtocol = 0x01,
  974.     kUSBPrinterBidirectionalProtocol = 0x02
  975. };
  976.  
  977.  
  978. enum {
  979.     kServiceCategoryUSB            = FOUR_CHAR_CODE('usb ')        /* USB*/
  980. };
  981.  
  982. /* SOMETHING NEEDS TO BE DONE WITH THIS - */
  983. enum {
  984.     kUSBTypeIsHub                = FOUR_CHAR_CODE('hubd'),        /* Hub*/
  985.     kUSBTypeIsHID                = FOUR_CHAR_CODE('HIDd'),        /* Human Interface Device*/
  986.     kUSBTypeIsDisplay            = FOUR_CHAR_CODE('disp'),        /* Display */
  987.     kUSBTypeIsModem                = FOUR_CHAR_CODE('modm')        /* Modem*/
  988. };
  989.  
  990. enum {
  991.     kUSBDriverFileType            = FOUR_CHAR_CODE('ndrv'),
  992.     kUSBDriverRsrcType            = FOUR_CHAR_CODE('usbd'),
  993.     kUSBShimRsrcType            = FOUR_CHAR_CODE('usbs')
  994. };
  995.  
  996. enum {
  997.     kTheUSBDriverDescriptionSignature = FOUR_CHAR_CODE('usbd')
  998. };
  999.  
  1000. enum {
  1001.     kInitialUSBDriverDescriptor    = 0
  1002. };
  1003.  
  1004.  
  1005.  
  1006. typedef UInt32                             USBDriverDescVersion;
  1007. /*  Driver Loading Options*/
  1008. typedef UInt32                             USBDriverLoadingOptions;
  1009. enum {
  1010.     kUSBDoNotMatchGenericDevice    = 0x00000001,                    /* Driver's VendorID must match Device's VendorID*/
  1011.     kUSBDoNotMatchInterface        = 0x00000002,                    /* Do not load this driver as an interface driver.*/
  1012.     kUSBProtocolMustMatch        = 0x00000004,                    /* Do not load this driver if protocol field doesn't match.*/
  1013.     kUSBInterfaceMatchOnly        = 0x00000008                    /* Only load this driver as an interface driver.*/
  1014. };
  1015.  
  1016. enum {
  1017.     kClassDriverPluginVersion    = 0x00001100
  1018. };
  1019.  
  1020.  
  1021.  
  1022.  
  1023. struct USBDeviceInfo {
  1024.     UInt16                             usbVendorID;                /* USB Vendor ID*/
  1025.     UInt16                             usbProductID;                /* USB Product ID.*/
  1026.     UInt16                             usbDeviceReleaseNumber;        /* Release Number of Device*/
  1027.     UInt16                             usbDeviceProtocol;            /* Protocol Info.*/
  1028. };
  1029. typedef struct USBDeviceInfo            USBDeviceInfo;
  1030. typedef USBDeviceInfo *                    USBDeviceInfoPtr;
  1031.  
  1032. struct USBInterfaceInfo {
  1033.     UInt8                             usbConfigValue;                /* Configuration Value*/
  1034.     UInt8                             usbInterfaceNum;            /* Interface Number*/
  1035.     UInt8                             usbInterfaceClass;            /* Interface Class*/
  1036.     UInt8                             usbInterfaceSubClass;        /* Interface SubClass*/
  1037.     UInt8                             usbInterfaceProtocol;        /* Interface Protocol*/
  1038. };
  1039. typedef struct USBInterfaceInfo            USBInterfaceInfo;
  1040. typedef USBInterfaceInfo *                USBInterfaceInfoPtr;
  1041.  
  1042. struct USBDriverType {
  1043.     Str31                             nameInfoStr;                /* Driver's name when loading into the Name Registry.*/
  1044.     UInt8                             usbDriverClass;                /* USB Class this driver belongs to.*/
  1045.     UInt8                             usbDriverSubClass;            /* Module type*/
  1046.     NumVersion                         usbDriverVersion;            /* Class driver version number.*/
  1047. };
  1048. typedef struct USBDriverType            USBDriverType;
  1049. typedef USBDriverType *                    USBDriverTypePtr;
  1050.  
  1051. struct USBDriverDescription {
  1052.     OSType                             usbDriverDescSignature;        /* Signature field of this structure.*/
  1053.     USBDriverDescVersion             usbDriverDescVersion;        /* Version of this data structure.*/
  1054.     USBDeviceInfo                     usbDeviceInfo;                /* Product & Vendor Info*/
  1055.     USBInterfaceInfo                 usbInterfaceInfo;            /* Interface info*/
  1056.     USBDriverType                     usbDriverType;                /* Driver Info.*/
  1057.     USBDriverLoadingOptions         usbDriverLoadingOptions;    /* Options for class driver loading.*/
  1058. };
  1059. typedef struct USBDriverDescription        USBDriverDescription;
  1060. typedef USBDriverDescription *            USBDriverDescriptionPtr;
  1061. /*
  1062.    Dispatch Table
  1063.    Definition of class driver's HW Validation proc.
  1064. */
  1065. typedef CALLBACK_API_C( OSStatus , USBDValidateHWProcPtr )(USBDeviceRef device, USBDeviceDescriptorPtr pDesc);
  1066. /*
  1067.    Definition of class driver's device initialization proc.
  1068.    Called if the driver is being loaded for a device
  1069. */
  1070. typedef CALLBACK_API_C( OSStatus , USBDInitializeDeviceProcPtr )(USBDeviceRef device, USBDeviceDescriptorPtr pDesc, UInt32 busPowerAvailable);
  1071. /* Definition of class driver's interface initialization proc.*/
  1072. typedef CALLBACK_API_C( OSStatus , USBDInitializeInterfaceProcPtr )(UInt32 interfaceNum, USBInterfaceDescriptorPtr pInterface, USBDeviceDescriptorPtr pDevice, USBInterfaceRef interfaceRef);
  1073. /* Definition of class driver's finalization proc.*/
  1074. typedef CALLBACK_API_C( OSStatus , USBDFinalizeProcPtr )(USBDeviceRef device, USBDeviceDescriptorPtr pDesc);
  1075.  
  1076. typedef UInt32                             USBDriverNotification;
  1077. enum {
  1078.     kNotifySystemSleepRequest    = 0x00000001,
  1079.     kNotifySystemSleepDemand    = 0x00000002,
  1080.     kNotifyHubEnumQuery            = 0x00000006,
  1081.     kNotifyChildMessage            = 0x00000007,
  1082.     kNotifyDriverBeingRemoved    = 0x0000000B
  1083. };
  1084.  
  1085. /*
  1086.    Definition of driver's notificatipn proc.      
  1087.    Added refcon for 1.1 version of dispatch table
  1088. */
  1089. typedef CALLBACK_API_C( OSStatus , USBDDriverNotifyProcPtr )(USBDriverNotification notification, void *pointer, UInt32 refcon);
  1090.  
  1091. struct USBClassDriverPluginDispatchTable {
  1092.     UInt32                             pluginVersion;
  1093.     USBDValidateHWProcPtr             validateHWProc;                /* Proc for driver to verify proper HW*/
  1094.     USBDInitializeDeviceProcPtr     initializeDeviceProc;        /* Proc that initializes the class driver.*/
  1095.     USBDInitializeInterfaceProcPtr     initializeInterfaceProc;    /* Proc that initializes a particular interface in the class driver.*/
  1096.     USBDFinalizeProcPtr             finalizeProc;                /* Proc that finalizes the class driver.*/
  1097.     USBDDriverNotifyProcPtr         notificationProc;            /* Proc to pass notifications to the driver.*/
  1098. };
  1099. typedef struct USBClassDriverPluginDispatchTable USBClassDriverPluginDispatchTable;
  1100. typedef USBClassDriverPluginDispatchTable * USBClassDriverPluginDispatchTablePtr;
  1101. /* Hub defines*/
  1102.  
  1103.  
  1104. enum {
  1105.     kUSBHubDescriptorType        = 0x29
  1106. };
  1107.  
  1108. enum {
  1109.                                                                 /* Hub features */
  1110.     kUSBHubLocalPowerChangeFeature = 0,
  1111.     kUSBHubOverCurrentChangeFeature = 1,                        /* port features */
  1112.     kUSBHubPortConnectionFeature = 0,
  1113.     kUSBHubPortEnablenFeature    = 1,
  1114.     kUSBHubPortSuspecdFeature    = 2,
  1115.     kUSBHubPortOverCurrentFeature = 3,
  1116.     kUSBHubPortResetFeature        = 4,
  1117.     kUSBHubPortPowerFeature        = 8,
  1118.     kUSBHubPortLowSpeedFeature    = 9,
  1119.     kUSBHubPortConnectionChangeFeature = 16,
  1120.     kUSBHubPortEnableChangeFeature = 17,
  1121.     kUSBHubPortSuspendChangeFeature = 18,
  1122.     kUSBHubPortOverCurrentChangeFeature = 19,
  1123.     kUSBHubPortResetChangeFeature = 20
  1124. };
  1125.  
  1126.  
  1127. enum {
  1128.     kHubPortConnection            = 1,
  1129.     kHubPortEnabled                = 2,
  1130.     kHubPortSuspend                = 4,
  1131.     kHubPortOverCurrent            = 8,
  1132.     kHubPortBeingReset            = 16,
  1133.     kHubPortPower                = 0x0100,
  1134.     kHubPortSpeed                = 0x0200
  1135. };
  1136.  
  1137. enum {
  1138.     kHubLocalPowerStatus        = 1,
  1139.     kHubOverCurrentIndicator    = 2,
  1140.     kHubLocalPowerStatusChange    = 1,
  1141.     kHubOverCurrentIndicatorChange = 2
  1142. };
  1143.  
  1144. enum {
  1145.     off                            = false,
  1146.     on                            = true
  1147. };
  1148.  
  1149.  
  1150.  
  1151. struct hubDescriptor {
  1152.                                                                 /* See usbDoc pg 250?? */
  1153.     UInt8                             dummy;                        /* to align charcteristics */
  1154.  
  1155.     UInt8                             length;
  1156.     UInt8                             hubType;
  1157.     UInt8                             numPorts;
  1158.  
  1159.     UInt16                             characteristics;
  1160.     UInt8                             powerOnToGood;                /* Port settling time, in 2ms */
  1161.     UInt8                             hubCurrent;
  1162.  
  1163.                                                                 /* These are received packed, will have to be unpacked */
  1164.     UInt8                             removablePortFlags[8];
  1165.     UInt8                             pwrCtlPortFlags[8];
  1166. };
  1167. typedef struct hubDescriptor            hubDescriptor;
  1168.  
  1169.  
  1170.  
  1171. #if PRAGMA_STRUCT_ALIGN
  1172.     #pragma options align=reset
  1173. #elif PRAGMA_STRUCT_PACKPUSH
  1174.     #pragma pack(pop)
  1175. #elif PRAGMA_STRUCT_PACK
  1176.     #pragma pack()
  1177. #endif
  1178.  
  1179. #ifdef PRAGMA_IMPORT_OFF
  1180. #pragma import off
  1181. #elif PRAGMA_IMPORT
  1182. #pragma import reset
  1183. #endif
  1184.  
  1185. #ifdef __cplusplus
  1186. }
  1187. #endif
  1188.  
  1189. #endif /* __USB__ */
  1190.  
  1191.